The Scripting app supports adding interactivity to widgets and LiveActivity, allowing you to create dynamic and interactive UIs using Button and Toggle components. These controls can execute AppIntents to trigger actions, making your widgets and live activities more powerful.
An AppIntent defines a specific action that can be triggered by a control (e.g., a Button or Toggle) in a widget or LiveActivity UI. AppIntents enable seamless interaction and functionality by linking UI components with executable logic.
AppIntents can implement the following protocols:
AppIntent: General-purpose intents for triggering custom actions.AudioPlaybackIntent: Handles audio playback (e.g., play, pause, or toggle audio states).AudioRecordingIntent: Manages audio recording states (requires iOS 18+ and a LiveActivity to stay active during recording).LiveActivityIntent: Modifies or manages LiveActivity states.To use an AppIntent, it must first be registered in the app_intents.tsx file using the AppIntentManager.register method.
After registering an AppIntent, it can be linked to interactive components like Button and Toggle in your widget.tsx or LiveActivity UI file.
AppIntentManager.registerRegisters an AppIntent for use in widgets or LiveActivity UIs.
name (string): A unique name for the intent.protocol (AppIntentProtocol): Specifies the type of intent (e.g., AppIntent, AudioPlaybackIntent).perform (function): The function to execute when the intent is triggered.AppIntentFactory function that can be used to create instances of the registered intent.Button ComponentA tappable button that triggers an AppIntent.
title (string): The button’s label.intent (AppIntent<any>): The AppIntent to execute when the button is tapped.systemImage (optional): An SF Symbol to display on the button.Toggle ComponentA toggle switch that triggers an AppIntent when its value changes.
value (boolean): Indicates the toggle's state (on/off).intent (AppIntent<any>): The AppIntent to execute when the toggle is toggled.title (string): The toggle’s label.systemImage (optional): An SF Symbol to display with the toggle.Widget.reloadAll() within perform functions to update widgets dynamically after executing an intent.app_intents.tsx for organization and reusability.AudioPlaybackIntent) to match the intent's functionality.